import React from 'react';
import * as lodash from 'lodash';
import {Button, Checkbox, message} from 'antd';
import {WeaDateGroup} from 'ecCom';
import {WeaDialog, WeaSearchGroup, WeaFormItem, WeaInput, WeaSelect, WeaBrowser,WeaCheckbox} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import EField_New from './base/EField_New'
import EMoreAddress from './base/EMoreAddress'

// 我的邮件，数据来源
class Content_16_DataSource extends React.Component {
    state = {
        id: this.props.tabData.id,
        title: this.props.tabData.title || '',
        mailSource:this.props.tabData.mailSource || this.props.tabNew.mailSource.selected,
        datetype:this.props.tabData.datetype,
        star:this.props.tabData.star || this.props.tabNew.star.selected,
        waitdeal:this.props.tabData.waitdeal || this.props.tabNew.waitdeal.selected,
        mailStatu:this.props.tabData.mailStatu || this.props.tabNew.mailStatu.selected,
        attachmentnumber:this.props.tabData.attachmentnumber || this.props.tabNew.attachmentnumber.selected,
        datetype: eval(this.props.tabData.datetype) || ["0"],
        wenjianjiaxz:this.props.tabData.wenjianjiaxz || "",
        wenjianjia:this.props.tabData.wenjianjia || "1",
        wenjianjiaxzname:eval(this.props.tabData.wenjianjiaxzname),
        dates: [
            {name:getLabel('126831',"全部"),value:'0'},
            {name:getLabel('15537',"今天"),value:'1'},
            {name:getLabel('15539',"本周") ,value:'2'},
            {name:getLabel('520373',"本月"),value:'3'},
            {name:getLabel('520374',"本季"),value:'4'},
            {name:getLabel('15384',"本年"),value:'5'},
            {name:getLabel('27347',"上个月"),value:'7'},
            {name:getLabel('81716',"上一年"),value:'8'},
            {name:getLabel('32530',"指定日期范围"),value:'6'}
        ]
    };

    constructor(props) {
        super(props);
        this.getButtons = this.getButtons.bind(this);
        this.onOk = this.onOk.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }

    render() {
        const{ title,mailSource,datetype,star,waitdeal,mailStatu,attachmentnumber,dates,wenjianjia,wenjianjiaxz,wenjianjiaxzname} = this.state;
        const {tabNew} = this.props;
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@30o3k1`}
                className="portal-esetting-dialog"
                visible={true}
                title={getLabel(19480, '内容设置')}
                icon="icon-coms-portal"
                iconBgcolor='#1a57a0'
                style={{width: 660, height: 550}}
                hasScroll={true}
                buttons={this.getButtons()}
                onCancel={this.onCancel}
            >
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@xxng6h`} title={getLabel(520265, '基础设置')} needTigger={true} showGroup={true}>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@8xqt82`} label={getLabel(24986, '标题')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@y8lb6k`} inputType="multilang" isBase64={true} value={title} viewAttr={3} onChange={value => this.setState({title: value})}/>
                    </WeaFormItem>
                </WeaSearchGroup>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@pm5p50`} title={getLabel(520255, '来源设置')} needTigger={true} showGroup={true}>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@da2ex6`} label={getLabel(520256, '接收时间')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        <div style={{display: 'inline-block'}}>
                            <div style={{width: '200px'}}>
                                <WeaDateGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaDateGroup@zcrg9n`}
                                    isMobx
                                    value={datetype}
                                    datas={dates}
                                    onChange={(v)=> this.setState({datetype: v})}
                                />
                            </div>
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@t67bof`} label={getLabel(520257, '邮件类型')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        <div style={{display: 'inline-block'}}>
                            <div style={{width: '150px'}}>
                                <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@pzddzf`}

                                    options={
                                        tabNew.mailSource.options.map((item) => {
                                            return {key: item.key, selected: false, showname: item.value};
                                        })
                                    }
                                    value={mailSource}
                                    onChange={value => {
                                        this.setState({mailSource: value});
                                    }}
                                />
                            </div>
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@24hjq8`} label={getLabel(520258, '邮件状态')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        <div style={{display: 'inline-block'}}>
                            <div style={{width: '150px'}}>
                                <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@kcatkl`}
                                    options={
                                        tabNew.mailStatu.options.map((item) => {
                                            return {key: item.key, selected: false, showname: item.value};
                                        })
                                    }
                                    value={mailStatu}
                                    onChange={value => {
                                        this.setState({mailStatu: value});
                                    }}
                                />
                            </div>
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@3m4qx4`} label={getLabel(520264, '是否待办邮件')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        <div style={{display: 'inline-block'}}>
                            <div style={{width: '150px'}}>
                                <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@n23vmc`}
                                    options={
                                        tabNew.waitdeal.options.map((item) => {
                                            return {key: item.key, selected: false, showname: item.value};
                                        })
                                    }
                                    value={waitdeal}
                                    onChange={value => {
                                        this.setState({waitdeal: value});
                                    }}
                                />
                            </div>
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@wim1sk`} label={getLabel(520259, '是否星标邮件')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        <div style={{display: 'inline-block'}}>
                            <div style={{width: '150px'}}>
                                <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@x9r9ly`}
                                    options={
                                        tabNew.star.options.map((item) => {
                                            return {key: item.key, selected: false, showname: item.value};
                                        })
                                    }
                                    value={star}
                                    onChange={value => {
                                        this.setState({star: value});
                                    }}
                                />
                            </div>
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@59191f`} label={getLabel(520260, '是否包含附件')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                    <div style={{display: 'inline-block'}}>
                        <div style={{width: '150px'}}>
                            <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@3dg9i5`}
                                options={
                                    tabNew.attachmentnumber.options.map((item) => {
                                        return {key: item.key, selected: false, showname: item.value};
                                    })
                                }
                                value={attachmentnumber}
                                onChange={value => {
                                    this.setState({attachmentnumber: value});
                                }}
                            />
                        </div>
                    </div>
                </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@yabv1b`} label={getLabel(520261, '所属文件夹')} labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        <div style={{display: 'block',width: '150px',float:'left'}}>
                            <div style={{}}>
                                <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@4qiql4`}
                                    options={[
                                        {key: "1", selected: false, showname: getLabel(520262, '全部')},
                                        {key: "2", selected: false, showname: getLabel(520263, '选择')}
                                        ]}
                                    value={wenjianjia}
                                    onChange={value => {
                                        this.setState({wenjianjia: value});
                                    }}
                                />
                            </div>
                        </div>
                        {
                            wenjianjia == "2" ?
                        <div style={{display: 'block',width: '200px',marginLeft:'30px',float:'right'}}>

                                <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@onrm6e`}
                                    isSingle={false}
                                    type={"emailFolderidForPortal"}
                                    title={getLabel('18214','请选择')}
                                    replaceDatas={wenjianjiaxzname}
                                    onChange={(key, name, datas) => {
                                        this.setState({wenjianjiaxz: key,wenjianjiaxzname:datas});
                                    }}
                                />
                        </div>
                                :
                                ""
                        }

                    </WeaFormItem>
                </WeaSearchGroup>
            </WeaDialog>
        );
    }

    getButtons() {
        let buttons = [];
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@j83rve`} type="primary" onClick={this.onOk}>{getLabel(826, '确定')}</Button>);
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ov8f0f`} type="ghost" onClick={this.onCancel}>{getLabel(31129, '取消')}</Button>);
        return buttons;
    }
    onOk() {
        if (!this.state.title) {
            message.warning(getLabel(15859, '必要信息不完整！'));
        } else {
            const eMoreAddress = this.refs['eMoreAddress'] ? this.refs['eMoreAddress'].getSaveValues() : {};
            this.props.onOk({...this.state, ...eMoreAddress});
        }
    }
    onCancel() {
        this.props.onCancel();
    }
}

export default Content_16_DataSource;
